package Leetcode;

public class Leetcode_154 {
    public static int lastRemaining(int n, int m) {
        return f(n, m);
    }

    public static int f(int n, int m) {
        if (n == 1) {
            return 0;
        }
        int x = f(n - 1, m);
        return (m + x) % n;
    }

    public static void main(String[] args) {
        int n = 5, m = 3;
        System.out.println(lastRemaining(n,m));
    }
}
